import igraph as ig
import matplotlib.pyplot as plt

# 是否绘图的开关
is_plot = True
n_vertices = 10
edges = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 9), (7, 9), (8, 9)]
g = ig.Graph(n_vertices, edges)

id_list = list(range(0, 10))
g.vs["id"] = id_list
g.vs['weight'] = list(range(1, 13))

# 绘图
if is_plot:
    fig, ax = plt.subplots(figsize=(5, 5))
    ig.plot(
        g,
        target=ax,
        layout="circle",  # print nodes in a circular layout
        vertex_size=0.1,
        vertex_frame_width=4.0,
        vertex_frame_color="white",
        vertex_label=g.vs["id"],
        vertex_label_size=7.0
    )
    plt.show()

# 由0开始深度遍历
dfs = g.dfs(0)
print(dfs)
for n in g.dfsiter(0):
    print(n)

# 返回节点的度
print('ever node degree=====>', g.degree())
